import {
  wxGetUserProfile,
  fetchGetUserProfile
} from '../api/login'
export const judgeIsAuth = () => {
  const name = wx.getStorageSync('name')
  const avatar = wx.getStorageSync('avatar')
  return new Promise((resolve, reject) => {
    if (name && avatar) {
      resolve(true)

    } else {
      wxGetUserProfile().then(res => {
          const { nickName , avatarUrl} = res.userInfo
          return fetchGetUserProfile({
            name: nickName,
            avatar: avatarUrl,
          })

        })
        .then((res) => {
          console.log(res)
          const { realName, avatar} = res.data.info
          wx.setStorageSync('name', realName)
          wx.setStorageSync('avatar', avatar)
          resolve(true)
        })
        .catch(err => {
          // console.log(err)
          resolve(false)
        })

    }



  })

}